package hihocode;

import java.util.Scanner;

// 1502 最大子矩阵
public class MaxSubMartrix {

	public static void mainLow(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n, m, k;
		int[][] matrix;
		int minValue = 0;
		while(scanner.hasNext()){
			n = scanner.nextInt();
			m = scanner.nextInt();
			k = scanner.nextInt();
			matrix = new int[n][m];
			for(int i = 0; i < n ;i++){
				for (int j = 0; j < m; j++) {
					int val = scanner.nextInt();
					matrix[i][j] = val;
					minValue = Math.min(minValue, val);
				}
			}
			if(minValue > k){
				System.out.println(-1);
				continue;
			}
			getCount(matrix, k);
		}
		scanner.close();
	}

	//Runtime 4641ms
	private static void getCount(int[][] matrix, int k ) {
		int n = matrix.length;
		int m = matrix[0].length;
		
		//存储第i行的0...j的和
		int[][] rows = new int[n][m];
		for(int i = 0; i < n; i++){
			rows[i][0] = matrix[i][0];
			for(int j = 1; j < m; j++){
				rows[i][j] = rows[i][j - 1] + matrix[i][j]; 
			}
		}
		
		//存储第j列的0...i的和
		int[][] columns = new int[n][m];
		for(int j = 0; j < m; j++){
			columns[0][j] = matrix[0][j];
			for(int i = 1; i < n; i++){
				columns[i][j] = columns[i - 1][j] + matrix[i][j]; 
			}
		}
		
//		//存储了[0, 0] 到[i, j]的值
//		int[][] nums = new int[n][m];
//		nums[0][0] = matrix[0][0];
//		for (int j = 1; j < m; j++) {
//			nums[0][j] = nums[0][j - 1] + matrix[0][j];
//		}
//		for (int i = 1; i < n; i++) {
//			nums[i][0] = nums[i - 1][0] + matrix[i][0];
//			for (int j = 1; j < m; j++) {
//				nums[i][j] = nums[i][j - 1] + columns[i][j];
//			}
//		}
		
		//存储[0..i][0...j]的和
		int[][] rowsSum = new int[n][m];
		for (int i = 0; i < n; i++) {
			rowsSum[i][0] = columns[i][0];
			for (int j = 1; j < m; j++) {
				rowsSum[i][j] = rowsSum[i][j - 1] + columns[i][j];
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				System.out.print(rowsSum[i][j] + "  ");
			}
			System.out.println();
		}
		
		int curCount = 0;
		int maxCount = 0;
		
		//本来以为数据量会很大，因为这样子是O(n ^ 4)
		//没想到AC了
		
		//用的思路就是二维的Range Sum Query, 但是感觉代码没写好
		//因为Sum[i...j]是sum[j] - sum[i] + arr[i]
		//一维的写起来很简单，但是对于二维的就不是这样的了
		for(int i = 0; i < n; i++){
			for (int j = 0; j < m; j++) {
				for (int x = n - 1; x >= i; x--) {
					for (int y = m - 1; y >= j; y--) {
						//由于我们计算range sum的时候
						//sum[i...j] = array[i] - array[j - 1]
						//到了二维之后，所以我们就需要判断是否为i, j 是否0
						if(i >= 1 && j >= 1 && 
								rowsSum[x][y] - rowsSum[x][j - 1] - (rowsSum[i - 1][y] - 
										rowsSum[i - 1][j - 1]) <= k){
							curCount = (x - i + 1) * (y - j + 1);
							maxCount = Math.max(maxCount, curCount);
							//注意这里的break，找到最大的之后我们就不继续找了
							break;
						}else if(j == 0 && i >= 1 && rowsSum[x][y] - rowsSum[i - 1][y] <= k){
							curCount = (x - i + 1) * (y - j + 1);
							maxCount = Math.max(maxCount, curCount);
							break;
						}else if(i == 0 && j >= 1 && rowsSum[x][y] - rowsSum[x][j - 1] <= k){
							curCount = (x + 1) * (y - j + 1);
							maxCount = Math.max(maxCount, curCount);
							break;
						}else if(rowsSum[x][y] <= k){
							curCount = (x + 1) * (y + 1);
							maxCount = Math.max(maxCount, curCount);
							break;
						}
					}
				}
			}
		}
		System.out.println(maxCount);
	}
	
	
	private static final int MAX = 252;
	
	
	//用类似最长无重复子串的思想（尺取法）
	// Runtime 	4484ms, C++代码Runtime 173ms
	//参见http://www.cnblogs.com/aiterator/p/6684857.html
	//如果注释掉ios::sync_with_stdio(false);
	//C++运行时间Runtime		242ms
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n, m, k;
		int[][] matrix = new int[MAX][MAX];
		while(scanner.hasNext()){
			n = scanner.nextInt();
			m = scanner.nextInt();
			k = scanner.nextInt();
			//matrix[i][j] 表示的是[0][0] -> [i][j] 的和 
			for(int i = 1; i <= n ;i++){
				for (int j = 1; j <= m; j++) {
					matrix[i][j] = scanner.nextInt();
					matrix[i][j] += matrix[i - 1][j] - matrix[i - 1][j - 1] + matrix[i][j - 1]; 
				}
			}
			int ans = 0;
			//N * N枚举行O(N*N)，用尺取法取列，总时间复杂度O(N*N*N)
			for(int i = 1; i <= n ;i++){
				for (int j = i; j <= n; j++) {
					//双指针，b相当于left，index相当于right，表示现在的下标
					for(int b = 1, index = 1; ;){
						while(index <= m && (matrix[j][index]  - matrix[i - 1][index] - matrix[j][b - 1]
								+ matrix[i - 1][b - 1]) <= k){
							index++;
						}
						//这里为什么不是index - b + 1呢？因为index++了才退出的循环
						ans = Math.max(ans, (j - i + 1) * (index - b));
						if(index > m){
							break;
						}
						while(b <= m && (matrix[j][index]  - matrix[i - 1][index] - matrix[j][b - 1]
								+ matrix[i - 1][b - 1]) > k){
		                    b++;
						}
					}
				}
			}
			if(ans == 0){
				System.out.println(-1);
			}else{
				System.out.println(ans);
			}
		}
		scanner.close();
	}
}
